﻿
using System;
using System.Threading.Tasks;

namespace Okarito.Utility
{
    /// <summary>
    /// Utility methods for working with <see cref="Task"/>.
    /// </summary>
    public static class TaskUtility
    {
        /// <summary>
        /// Executes the specified tsak 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="task"></param>
        /// <returns></returns>
        public static T AsSynchronous<T>(this Task<T> task)
        {
            try
            {
                return task.Result;
            }
            catch (AggregateException ex)
            {
                throw ex.InnerException;
            }
        }
    }
}
